function K = linkItemStatementCollection_Analysis(Q,A)

%this function will insert and item to collection (eg CID1) retreive the
%item_id and insert the item as a statement linking it to and rule using
%rule_id.  Using the item_id it will then attach it to a collection using
%and collection_id2. Finally, the two collections (CID1 and
%collection_id2 will be linked.
%
%Romesh Stanislaus May 2010

%Variables that change
BB.collection_id = 186; % i.e. Analyses etc
BB.notes = 'EIG121_91'; %%%
CC.collection_id = 190; %%%16811;
CC.notes = 'EIG121_91_Analysis'; %%%
rule_id_1 = 379; %insert RULE ID for LINKING %%%%%%%%%%%%%%

%%Anal is a variable with rows and columns 
[rows,cols] = size(A);
%the FIRST ROW will contain the RULE_ID's corrosponding to the column
%read in from file/matrix
for rws = 2:rows
    %I_1 = insertItem(Q,22517,''); %I_1.item_id contains the item_id
    %BB.collection_id = 186; %22508;% i.e. Analyses etc
    %BB.notes = 'IGFBP1_log'; %%%
    I_1 = insertCommon(Q, 'item', BB);
    disp(['------Inserting entry number---',num2str(rws),'  out of  ',num2str(rows)]);
    for cls = 1:cols
        %generate s3ql for the item entered as a statement to a collection with a rule
        rule_id = num2str(A{1,cls}); %1st row is the rules...
        %S = insertStatement(Q, I_1.item_id ,rule_id,  A{rws,cls}); %S.statement_id is the statement_id
        F.item_id = I_1.item_id;
        F.rule_id = rule_id;
        F.value = A{rws,cls};
        S = insertCommon(Q, 'statement', F);
        pause(0.1)
    end
    %start linking one collection (eg.EIG121_91) to another(eg.Data)
    %I_2 = insertItem(Q, 16811,'IGFBP1_log_Analysis'); %need to change for diff collections
    %CC.collection_id = 198; %%%16811;
    %CC.notes = 'IGFBP1_log_Analysis'; %%%
    I_2 = insertCommon(Q, 'item', CC);
    
    %insert RULE ID for LINKING %%%%%%%%%%%%%%
    %rule_id_1 = 426; %%%22523; %need to change for diff collections
    %link the two items into a Statement by a rule%%%%%%%%%%%
    %S = insertStatement(Q, I_2.item_id, rule_id_1, I_1.item_id);
    DD.item_id = I_2.item_id;
    DD.rule_id = rule_id_1;
    DD.value = I_1.item_id;
    S = insertCommon(Q, 'statement', DD);
    pause(0.1)
end
K='Done Inserting...';
